package com.ruoyi.web.controller.golang;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CommunityTag;
import com.ruoyi.system.service.ICommunityTagService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 社群标签关系Controller
 * 
 * @author ruoyi
 * @date 2025-01-12
 */
@Controller
@RequestMapping("/system/tag")
public class CommunityTagController extends BaseController
{
    private String prefix = "system/tag";

    @Autowired
    private ICommunityTagService communityTagService;

    @RequiresPermissions("system:tag:view")
    @GetMapping()
    public String tag()
    {
        return prefix + "/tag";
    }

    /**
     * 查询社群标签关系列表
     */
    @RequiresPermissions("system:tag:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CommunityTag communityTag)
    {
        startPage();
        List<CommunityTag> list = communityTagService.selectCommunityTagList(communityTag);
        return getDataTable(list);
    }

    /**
     * 导出社群标签关系列表
     */
    @RequiresPermissions("system:tag:export")
    @Log(title = "社群标签关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CommunityTag communityTag)
    {
        List<CommunityTag> list = communityTagService.selectCommunityTagList(communityTag);
        ExcelUtil<CommunityTag> util = new ExcelUtil<CommunityTag>(CommunityTag.class);
        return util.exportExcel(list, "社群标签关系数据");
    }

    /**
     * 新增社群标签关系
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存社群标签关系
     */
    @RequiresPermissions("system:tag:add")
    @Log(title = "社群标签关系", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CommunityTag communityTag)
    {
        return toAjax(communityTagService.insertCommunityTag(communityTag));
    }

    /**
     * 修改社群标签关系
     */
    @RequiresPermissions("system:tag:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        CommunityTag communityTag = communityTagService.selectCommunityTagById(id);
        mmap.put("communityTag", communityTag);
        return prefix + "/edit";
    }

    /**
     * 修改保存社群标签关系
     */
    @RequiresPermissions("system:tag:edit")
    @Log(title = "社群标签关系", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CommunityTag communityTag)
    {
        return toAjax(communityTagService.updateCommunityTag(communityTag));
    }

    /**
     * 删除社群标签关系
     */
    @RequiresPermissions("system:tag:remove")
    @Log(title = "社群标签关系", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(communityTagService.deleteCommunityTagByIds(ids));
    }
}
